package com.mt.channel.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.channel.entity.ChannelMenuEntity;
import com.mt.channel.mapper.ChannelMenuMapper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;

@Component
public class ChannelMenuServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ChannelMenuServiceModel.class);

    @Autowired
    private ChannelMenuMapper channelMenuMapper;

    public ServiceResult<List<ChannelMenuEntity>> selectList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        Assert.notNull(this.channelMenuMapper, "Property 'channelMenuMapper' is required.");
        ServiceResult<List<ChannelMenuEntity>> result = new ServiceResult<List<ChannelMenuEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }
            List<ChannelMenuEntity> channelMenuEntityMapperResult = this.channelMenuMapper.selectList(params);
            result.setResult(channelMenuEntityMapperResult);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMenuServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<ChannelMenuEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.channelMenuMapper, "Property 'channelMenuMapper' is required.");
        ServiceResult<ChannelMenuEntity> result = new ServiceResult<ChannelMenuEntity>();
        try {
            result.setResult(this.channelMenuMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMenuServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(ChannelMenuEntity channelMenuEntity) {
        Assert.notNull(this.channelMenuMapper, "Property 'channelMenuMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelMenuMapper.insert(channelMenuEntity);
            if (save > 0) {
                id = channelMenuEntity.getChannelMenuId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMenuServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(ChannelMenuEntity channelMenuEntity) {
        Assert.notNull(this.channelMenuMapper, "Property 'channelMenuMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelMenuMapper.updateByPrimaryKeySelective(channelMenuEntity);
            if (save > 0) {
                id = channelMenuEntity.getChannelMenuId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMenuServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(ChannelMenuEntity channelMenuEntity) {
        Assert.notNull(this.channelMenuMapper, "Property 'channelMenuMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelMenuMapper.updateByPrimaryKeySelective(channelMenuEntity);
            if (save > 0) {
                id = channelMenuEntity.getChannelMenuId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMenuServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKey(ChannelMenuEntity channelMenuEntity) {
        Assert.notNull(this.channelMenuMapper, "Property 'channelMenuMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.channelMenuMapper.updateByPrimaryKey(channelMenuEntity);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMenuServiceModel][updateByPrimaryKey]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer channelMenuId) {
        Assert.notNull(this.channelMenuMapper, "Property 'channelMenuMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.channelMenuMapper.doUpdateByPrimaryKey(channelMenuId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMenuServiceModel][deleteByPrimaryKey]:query update occur exception", e);
        }
        return result;
    }
}
